#ifndef _TWITTER_RESOURCE_DIRECT_MESSAGES_H_
#define _TWITTER_RESOURCE_DIRECT_MESSAGES_H_
#include "object.h"
NS_BEGIN(Twit)
NS_BEGIN(Resource)
NS_BEGIN(DirectMessage)

typedef Object<Value::DirectMessage>    OVDM;
typedef Object<Value::DirectMessages>   OVDMs;

struct ObjectDirectMessages:public OVDM
{
	ObjectDirectMessages(IOAuth& o, const char* file):OVDM(o,"direct_messages",file){}
};


/**
* @brief 
*  Returns the 20 most recent direct messages sent to the authenticating user. 
*  The XML and JSON versions include detailed information about the sender and recipient user.
*/
class DirectMessages:public OVDMs
{
public:
	DirectMessages(IOAuth& o):OVDMs(o,"direct_messages","")
	{
		setConstraints(true, true);
		setPath("");
		setFile("direct_messages");
	}

   /**
   * @param v
   *  Returns results with an ID greater than (that is, more recent than) the specified ID. 
   *  There are limits to the number of Tweets which can be accessed through the API. 
   *  If the limit of Tweets has occured since the since_id, the since_id will be 
   *  forced to the oldest ID available.
   *  ex.) http://api.twitter.com/1/direct_messages.json?since_id=12345
   */
	void setSinceId(Value::UniqueID id){ setParam("since_id",id.toString().c_str());	}

   /**
   * @param v
   *  Returns results with an ID less than (that is, older than) or equal to the specified ID.
   *  http://api.twitter.com/1/direct_messages.json?max_id=54321
   */
	void setMaxId(Value::UniqueID id){ setParam("max_id", id.toString().c_str()); }

   /**
   * @param v
   *  Specifies the number of records to retrieve. Must be less than or equal to 200.
   */
	void setCount(size_t v){ setParam("count", (int)v); }

   /**
   * @param v
   *  Specifies the page of results to retrieve.
   */
	void setPage(size_t v){ setParam("page", (int)v); }

	void setIncludeEntities(bool v){ setParam("include_entities", v); }
};


/**
* @brief 
*  Returns the 20 most recent direct messages sent by the authenticating user. 
*  The XML and JSON versions include detailed information about the sender and recipient user.
*/
class Sent:public OVDMs
{
public:
	Sent(IOAuth& o):OVDMs(o,"direct_messages","sent")
	{
		setConstraints(true,true);
	}

    /**
   * @param v
   *  Returns results with an ID greater than (that is, more recent than) the specified ID. 
   *  There are limits to the number of Tweets which can be accessed through the API. 
   *  If the limit of Tweets has occured since the since_id, the since_id will be 
   *  forced to the oldest ID available.
   *  ex.) http://api.twitter.com/1/direct_messages.json?since_id=12345
   */
	void setSinceId(Value::UniqueID id){ setParam("since_id", id.toString().c_str());	}

   /**
   * @param v
   *  Returns results with an ID less than (that is, older than) or equal to the specified ID.
   *  http://api.twitter.com/1/direct_messages.json?max_id=54321
   */
	void setMaxId(Value::UniqueID id){ setParam("max_id", id.toString().c_str());	}

   /**
   * @param v
   *  Specifies the number of records to retrieve. Must be less than or equal to 200.
   */
	void setCount(size_t v){ setParam("count", (int)v);	}

   /**
   * @param v
   *  Specifies the page of results to retrieve.
   */
	void setPage(size_t v){ setParam("page", (int)v);	}

	void setIncludeEntities(bool v){ setParam("include_entities", v);	}
};

/**
* @brief 
*  Sends a new direct message to the specified user from the authenticating user. 
*  Requires both the user and text parameters and must be a POST. 
*  Returns the sent message in the requested format if successful.
*/
struct New:public ObjectDirectMessages
{
	New(IOAuth& o):ObjectDirectMessages(o,"new")
	{
		setConstraints(true,false);
		setRequestMethod(RequestMethodPost);
	}
private:
   inline bool request(){ return ObjectDirectMessages::request(); }
public:

   /**
   * @param user user id of screen name
   *  screen_name
   *     The screen name of the user who should receive the direct message. 
   *     Helpful for disambiguating when a valid screen name is also a user ID.
   *     http://api.twitter.com/1/direct_messages/new.json?screen_name=noradio
   *  user_id
   *     The ID of the user who should receive the direct message. 
   *     Helpful for disambiguating when a valid user ID is also a valid screen name.
   *     http://api.twitter.com/1/direct_messages/new.json?user_id=12345
   * @param text
   *  The text of your direct message. Be sure to URL encode as necessary, 
   *  and keep the message under 140 characters.
   *  http://api.twitter.com/1/direct_messages/new.json?text=Meet me behind the cafeteria after school
   */
   bool request(std::string screenName, std::wstring text)
   {
	   setParam("screen_name", screenName.c_str());
	   setParam("text", Convert::UnicodeToUtf8(text).c_str());
	   return ObjectDirectMessages::request();
   }
   bool request(Value::UniqueID userId, std::wstring text)
   {
		setParam("user_id", userId.toString().c_str());
		setParam("text", Convert::UnicodeToUtf8(text).c_str());
		return ObjectDirectMessages::request();
   }

   Value::DirectMessage& get(std::string screenName, std::wstring text)
   {
	   setParam("screen_name", screenName.c_str());
	   setParam("text", Convert::UnicodeToUtf8(text).c_str());
	   return ObjectDirectMessages::get();
   }

   Value::DirectMessage& get(Value::UniqueID userId, std::wstring text)
   {
	   setParam("user_id", userId.toString().c_str());
	   setParam("text", Convert::UnicodeToUtf8(text).c_str());
	   return ObjectDirectMessages::get();
   }

   void setIncludeEntities(bool v){ setParam("include_entities", v);	}
};

/**
* @brief 
*  Destroys the direct message specified in the required ID parameter. 
*  The authenticating user must be the recipient of the specified direct message.
*/
struct Destroy:public ObjectDirectMessages
{
	Destroy(IOAuth& o):ObjectDirectMessages(o,"")
	{
		setConstraints(true,false);
		std::string path = getPath();
		path += "/destroy";
		setPath(path.c_str());
		setRequestMethod(RequestMethodPost);
	}
private:
   inline bool request(){ return ObjectDirectMessages::request(); }
public:

   /**
   * @param id The ID of the direct message to delete.
   *  ex.) http://api.twitter.com/1/direct_messages/destroy/1234.json
   */
   bool request(Value::UniqueID id)
   {
	   setFile(id.toString().c_str());
	   return ObjectDirectMessages::request();
   }
   Value::DirectMessage& get(Value::UniqueID id)
   {
	   setFile(id.toString().c_str());
	   return ObjectDirectMessages::get();
   }

   void setIncludeEntities(bool v)
   {
	   setParam("include_entities", v);
   }
};
NS_END;

DeclareResourceClass(CDirectMessages)
CDirectMessages(IOAuth& o):DirectMessages(o), New(o), Sent(o), Destroy(o){}
public:
DirectMessage::DirectMessages   DirectMessages;
DirectMessage::New              New;
DirectMessage::Sent             Sent;
DirectMessage::Destroy          Destroy;
EndResourceClass;
NS_END;
NS_END;
#endif /* _TWITTER_RESOURCE_DIRECT_MESSAGES_H_ */
